package org.huqiwen.blog.dao;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

/***
 * 单态模式进行数据库的连接
 * @author Administrator
 *
 */
public class DataSource {
	private static Connection conn;
	private DataSource(){
		try {
			Class.forName("com.mysql.jdbc.Driver");
			conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/myblogs", "root", "huqiwen");
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
	public static Connection getConnection(){
		if(null==conn){
			new DataSource();
		}
		return conn;
	}
}
